package leetcode.offer;

import java.util.Stack;

/**
 * ClassName: MinStack
 * Description:
 * date: 2021-10-27 17:36
 *
 * @author liyifan
 */
public class MinStack {

    private Stack<Integer> mainStack;

    private Stack<Integer> minStack;

    public MinStack() {
        mainStack = new Stack<>();
        minStack = new Stack<>();
    }

    public void push(int x) {
        mainStack.push(x);
        if (minStack.empty() || minStack.peek() > x) {
            minStack.push(x);
        } else {
            minStack.push(minStack.peek());
        }
    }

    public void pop() {
        minStack.pop();
        mainStack.pop();
    }

    public int top() {
        return mainStack.peek();
    }

    public int min() {
        return minStack.peek();
    }
}
